
// 公共路径
import axios from "axios";
axios.defaults.baseURL='http://wthrcdn.etouch.cn/weather_mini'
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    return response;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});
const reqeust = (url, method, params, data) => {
    return new Promise((resolve, reject) => {
        axios({
            url: url,
            method: method,
            params: params,
            data: data,

        }).then(
            (res) => {
                resolve(res.data);
            },
            (error) => {
                reject(error);
            }
        );
    });
}
const post = (url, data = {}) => {
    return reqeust(url, "POST", null, data);
}
const get = (url, params = {}) => {
    return reqeust(url, "GET", params, null);
}
export default { post, get }